package com.lhsy.djcloud.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lhsy.djcloud.entity.Department;
import com.lhsy.djcloud.mapper.DepartmentMapper;
import com.lhsy.djcloud.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangzw
 * @since 2020-09-14
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
    @Autowired private DepartmentMapper departmentMapper;
    @Override
    public List<Department> getAllDepartments(Integer tenantId) {
        return departmentMapper.getAllDepartmentsByParentId(tenantId,0);
    }

    @Override
    public List<Department> selectByPid(Integer fid) {
        QueryWrapper<Department> queryWrapper = new QueryWrapper<>();
        Department department = new Department();
        department.setFid(fid);
        queryWrapper.setEntity(department);
        return departmentMapper.selectList(queryWrapper);
    }

    @Override
    public int delete(Integer id) {
        return departmentMapper.deleteById(id);
    }

    @Override
    public List<Department> selectChildrenDept(Integer tenantId,Integer id) {
        return departmentMapper.getAllDepartmentsByParentId(tenantId, id);
    }

    @Override
    public List<Department> getChildrenDept(Integer tenantId,String params) {

        return departmentMapper.getChildrenDept(tenantId,params);
    }

    @Override
    public List<Department> getByLevel(Integer tenantId, Integer level) {

        return departmentMapper.getByLevel(tenantId,level);
    }

    @Override
    public List<Department> selectNoSelf(Integer userId,Integer tenantId) {

        return departmentMapper.selectNoSelf(userId,tenantId);
    }
    @Override
    public List<Department> selectTreeList(Integer id,Integer tenantId) {

        return departmentMapper.selectTreeList(id,tenantId);
    }
}
